package com.itcat.controller;/*
 * @Author: gonhsl
 * @Date:2022-04-02-20:34
 * */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.SmsHomeBrand;
import com.itcat.service.SmsHomeBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/brand")
public class SmsHomeBrandController {
    @Autowired
    private SmsHomeBrandService smsHomeBrandService;
    /**
     * Description:
     * date: 2022/4/2 21:34
     * @author: chp
     * @since JDK 1.8
     */

    @GetMapping("/list")
    public CommonResult list(@RequestParam Integer pageNum,
                             @RequestParam Integer pageSize,
                             String brandName,
                             Integer recommendStatus){

        Page<SmsHomeBrand> brandPage = smsHomeBrandService.list(pageNum, pageSize, brandName, recommendStatus);
        CommonPage<SmsHomeBrand> restPage = CommonPage.restPage(brandPage);
        return CommonResult.success(restPage);
    }
    /**
     * Description:
     * date: 2022/4/2 21:34
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsHomeBrand> homeBrands){
        smsHomeBrandService.create(homeBrands);
        return CommonResult.success();
    }

    /**
     * Description:
     * date: 2022/4/2 21:34
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Integer> ids) {
        smsHomeBrandService.delete(ids);
        return CommonResult.success();
    }

    /**
     * Description:
     * date: 2022/4/2 21:34
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/update/recommendStatus")
    public CommonResult updateRecommendStatus(@RequestParam List<Integer> ids,
                                              @RequestParam  Integer recommendStatus) {
        smsHomeBrandService.updateRecommendStatus(ids,recommendStatus);
        return CommonResult.success();
    }

    /**
     * Description:修改推荐品牌排序
     * date: 2022/4/2 21:34
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/update/sort/{id}")
    public CommonResult updateSort(@PathVariable Integer id,
                                              @RequestParam Integer sort) {
        smsHomeBrandService.updateSort(id, sort);
        return CommonResult.success();
    }
}
